package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Word1;
import com.ruoyi.system.service.IWord1Service;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 词库管理Controller
 * 
 * @author dyl
 * @date 2023-04-17
 */
@Controller
@RequestMapping("/system/word")
public class Word1Controller extends BaseController
{
    private String prefix = "system/word";

    @Autowired
    private IWord1Service word1Service;

    @RequiresPermissions("system:word:view")
    @GetMapping()
    public String word()
    {
        return prefix + "/word";
    }

    /**
     * 查询词库管理列表
     */
    @RequiresPermissions("system:word:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Word1 word1)
    {
        startPage();
        List<Word1> list = word1Service.selectWord1List(word1);
        return getDataTable(list);
    }

    /**
     * 导出词库管理列表
     */
    @RequiresPermissions("system:word:export")
    @Log(title = "词库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Word1 word1)
    {
        List<Word1> list = word1Service.selectWord1List(word1);
        ExcelUtil<Word1> util = new ExcelUtil<Word1>(Word1.class);
        return util.exportExcel(list, "词库管理数据");
    }

    /**
     * 新增词库管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存词库管理
     */
    @RequiresPermissions("system:word:add")
    @Log(title = "词库管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Word1 word1)
    {
        return toAjax(word1Service.insertWord1(word1));
    }

    /**
     * 修改词库管理
     */
    @RequiresPermissions("system:word:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Word1 word1 = word1Service.selectWord1ById(id);
        mmap.put("word1", word1);
        return prefix + "/edit";
    }

    /**
     * 修改保存词库管理
     */
    @RequiresPermissions("system:word:edit")
    @Log(title = "词库管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Word1 word1)
    {
        return toAjax(word1Service.updateWord1(word1));
    }

    /**
     * 删除词库管理
     */
    @RequiresPermissions("system:word:remove")
    @Log(title = "词库管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(word1Service.deleteWord1ByIds(ids));
    }
}
